package com.westvalley.syn.address.prop;


import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

import com.jfinal.kit.LogKit;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.StrKit;

public class AddressProp {
	public static final String HR_CONFIG_FILE_PATH = PathKit.getWebRootPath() + File.separator + "WEB-INF" + File.separator + "prop" + File.separator + "InterfaceAddress.properties";
	private Properties prop;
	private String mode;	//接口模式

	
	public static AddressProp me(){
		return new AddressProp();
	}
	
	public static AddressProp me(String mode){
		return new AddressProp(mode);
	}
	
	public AddressProp(){
		init(null);
	}
	
	public AddressProp(String mode){
		init(mode);
	}
	
	private void init(String mode){
		this.prop = new Properties();
		try {
			this.prop.load(new FileInputStream(new File(HR_CONFIG_FILE_PATH)));
			this.mode = StrKit.isBlank(mode)? prop.getProperty("mode") : mode;
		} catch (Exception e) {
			LogKit.error("读取配置文件异常！", e);
		}
	}
	
	public String getPropValue(String key){
		return prop.getProperty(this.mode+"_"+key);
	}
	
	public String getMode() {
		return mode;
	}

	public void setMode(String mode) {
		this.mode = mode;
	}

}
